<!DOCTYPE html>
<#import "/common/common.html" as common>
<html>
<head>
	<@common.head title="微信wifi管理系统" keywords="" description=""/>
</head>
<body class="gray-bg">

    <div class="wrapper wrapper-content animated fadeInRight">
    	<div class="row">
            <div class="col-sm-12" id="userListDiv">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <div class="rboor form-inline" id="searchbar">
                            <div class="form-group">
                                <label>门店名称：</label>
                                <input type="text" name="business_name" placeholder="请输入门店名称" class="form-control input-sm">
                            </div>
                            <div class="form-group">
                                <label>所属公众号：</label>
                                <#if wxusers??>
                              		<select id="wxuser_id" name="wxuser_id" class="form-control input-sm inline">
                              			<option value="">全部</option>
									<#list wxusers as wxuser>
										<option value="${wxuser.id}">${wxuser.name}</option>
									</#list>
								</select>
								</#if>
                            </div>
                            <button class="btn btn-primary btn-sm" onclick="search()">搜索</button>
                            <button class="btn btn-warning btn-sm" onclick="clearSearch()">清空</button>
						</div>
                    	 <!-- 操作按钮 -->
						<div class="rboor" id="toolbar">
							<button id="add" onclick="add()" class="btn btn-primary"><i class="fa fa-plus"></i> 新增设备</button>
							<button id="remove" onclick="remove()" class="btn btn-danger"><i class="fa fa-trash"></i> 清空门店网络及设备</button>
					    </div>
                         <table id="table"
                         	   data-toolbar="#toolbar"
				               data-url="${basePath}/wxstore/pageList"
				               data-id-field="id"
				               data-click-to-select="true"
				               data-side-pagination="server"
				               data-pagination="true"
				               data-icon-size="outline"
				               data-show-refresh="true"
				               data-show-columns="true"
				               data-show-export="true" 
				               data-show-toggle="true"
				               data-page-size="20"
				               data-page-list="[20, 100, ALL]"
				               data-pagination-first-text="首页"
							   data-pagination-pre-text="上一页"
							   data-pagination-next-text="下一页"
							   data-pagination-last-text="末页"
				               >
				        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Page-Level Scripts -->
    <!-- 新增设备窗口 -->
    <@common.remoteModal />
    
    <script>
	$(function () {
		list();
	});
	
	function list(){
		$('#table').bootstrapTable({
	        columns: [
                {
                    field: 'state',
                    checkbox: true,
                    align: 'center',
                    valign: 'middle'
                }, {
                    title: 'ID',
                    field: 'id',
                    align: 'left',
                    visible: false,
                    switchable: false,
                    valign: 'middle'
                }, {
                    title: '门店名称',
                    field: 'business_name',
                    align: 'left',
                    valign: 'middle'
                }, {
                    title: '所属公众号',
                    field: 'wxuser_name',
                    align: 'left',
                    valign: 'middle'
                }, {
                    title: '已添加ssid数',
                    field: 'device_count',
                    align: 'left',
                    valign: 'middle',
                    formatter: function(value, row, index){
	                	return value + " / 100";
	                }
                }, {
                    title: '已添加设备数',
                    field: 'mac_count',
                    align: 'left',
                    valign: 'middle'
                }, {
                    title: '操作',
                    field: 'categories',
                    align: 'left',
                    valign: 'middle',
                    formatter: function(value, row, index){
	                	return "<a href='${basePath}/wxstore/detail?id=" + row.id + "'>查看详情</a>";
	                }
                }
	        ],
	        queryParams: function(params) {
	            $('#searchbar').find('select[name], input[name]').each(function () {
	                params[$(this).attr('name')] = $(this).val();
	            });
	        	return params;
	        },
	        queryParamsType: "" // When requesting remote data, you can send additional parameters by modifying queryParams. If queryParamsType = 'limit', the params object contains: 
					// limit, offset, search, sort, order Else, it contains: 
	        		// pageSize, pageNumber, searchText, sortName, sortOrder. 
	        		// Return false to stop request.
    	}).on('check.bs.table uncheck.bs.table ' +
                'check-all.bs.table uncheck-all.bs.table', function () {
	    	//$("#edit").prop('disabled', $("#table").bootstrapTable('getSelections').length != 1);
            //$("#remove").prop('disabled', !$("#table").bootstrapTable('getSelections').length);
            //selections = getIdSelections();
        });

	    $(window).resize(function () {
	        $('#table').bootstrapTable('resetView');
	    });
	}
	
	// 清空门店网络及设备
    <@common.remove url="${basePath}/wxstore/clearDevice"/>
	
	// 新增设备
	function add(){
		var $selections = $("#table").bootstrapTable("getSelections");
		if($selections.length > 1) {
			toastr.warning("很抱歉,一次只能选择一条记录.","");
			return;
		}else if($selections.length == 0) {
			toastr.warning("您没有选择任何项,请您选中后操作.","");
			return;
		}
		var $selection = $selections[0];
		if($selection.device_count >= 100) {
			swal("操作失败！", "该门店下已经超过100个ssid,无法添加！", "error");
			return;
		}
		
		$("#formModal").modal({
    	    remote: "${basePath}/wxdevice/goAdd?storeId="+$selection.id
    	})
	}
	
	// 搜索
	function search(){
	    $("#table").bootstrapTable('refresh',{query: {pageNumber: 1}});
	}
	
	// 清空搜索条件
	function clearSearch(){
		 $('#searchbar').find('select[name], input[name]').each(function () {
             $(this).val("");
         });
		 search();
	}
	
    </script>
</body>

</html>